<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome White Paper!</title>
</head>
<body>
<?php
	require_once( 'core_DataBaseConnect.php' );
	require_once( 'core_Response.php' );
	require_once( 'core_ErrorCode.php' );
	require_once( '_configs.php' );
	
	$id = $_GET[ 'mail' ];
	$key = $_GET[ 'active' ];
	
	$con = new DataBaseConnect();
	try{
		$con->connect( configs::DATABASE_HOST, configs::DATABASE_USERNAME, configs::DATABASE_PASS, configs::DATABASE_DBNAME );
	}catch( Exception $e )
	{
		// 접속 실폐
		echo '['.configs::ACTIVEMAIL_SERVICE_TITLE.']데이터 베이스 접속에 오류입니다.'.$e->getMessage();
		exit;
	}
	
	// 유저 정보 확인
	$query = 'SELECT * FROM '.configs::TABLE_MEMBER." WHERE ID='$id' AND ACTIVE_KEY='$key'";
	$result = $con->query( $query );
	
	$fetch = DataBaseConnect::fetch_assoc($result);
	if($fetch['STATUS'] == '1'){
		// 이미 승인됨
		echo '['.configs::ACTIVEMAIL_SERVICE_TITLE.'] 이미 승인됨. Your Email has already been verified.';
	}else{
		$cnt = DataBaseConnect::num_rows( $result );
		if($cnt=='1'){
			// 상태 갱신시킴
			$query = 'UPDATE '.configs::TABLE_MEMBER." SET STATUS='1' WHERE ID='$id' AND ACTIVE_KEY='$key'";
			$result = $con->query( $query );
			if($result){
				// 갱신됨
				echo '['.configs::ACTIVEMAIL_SERVICE_TITLE.']이메일이 승인되었음. Email Verified';
			}else{
				// 시스템 에러
				echo '['.configs::ACTIVEMAIL_SERVICE_TITLE.']시스템 에러. System Faced an error while updating your status.';
			}
		}else{
			// 유효한 이메일 혹은 인증키가 아님
			echo '['.configs::ACTIVEMAIL_SERVICE_TITLE.']유효한 이메일 혹은 인증키가 아님. Unable to verify your email address.';
		}
	}
	$con->close();
	exit;
?>
</body>
</html>